#include "mainwindow.h"
#include <QToolBar>
#include <QMenu>
#include <QMenuBar>
#include <QApplication> // for qApp macro
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    m_centralWidget = new CentralWidget(this);

    m_newJobAction = new QAction(QIcon(), tr("New job"), this);
    m_resumeJobAction = new QAction(QIcon(), tr("Start/Resume job"), this);
    m_pauseJobAction = new QAction(QIcon(), tr("Pause job"), this);
    m_removeJobAction = new QAction(QIcon(), tr("Remove job"), this);

    connect(m_newJobAction, SIGNAL(triggered()),
            this, SLOT(newJob()));
    connect(m_resumeJobAction, SIGNAL(triggered()),
            this, SLOT(resumeJob()));
    connect(m_pauseJobAction, SIGNAL(triggered()),
            this, SLOT(pauseJob()));
    connect(m_removeJobAction, SIGNAL(triggered()),
            this, SLOT(removeJob()));

    // File menu
    QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(m_newJobAction);
    fileMenu->addAction(m_resumeJobAction);
    fileMenu->addAction(m_pauseJobAction);
    fileMenu->addAction(m_removeJobAction);
    fileMenu->addSeparator();
    fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, SLOT(close()));

    // Help menu
    QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
//    helpMenu->addAction(tr("&About"), this, SLOT(about()));
    helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));

    // Top toolbar
    QToolBar *toolbar = new QToolBar(tr("Tools"));
    addToolBar(Qt::TopToolBarArea, toolbar);
    toolbar->setMovable(false);
    toolbar->addAction(m_newJobAction);
    toolbar->addAction(m_resumeJobAction);
    toolbar->addAction(m_pauseJobAction);
    toolbar->addAction(m_removeJobAction);
    toolbar->addSeparator();

    setCentralWidget(m_centralWidget);
}

MainWindow::~MainWindow()
{
}

void MainWindow::newJob()
{
    qDebug() << "TODO: Here we need to open the user-friendly dialog";
}

void MainWindow::resumeJob()
{
    qDebug() << "TODO: Here we need to resume the job";
}

void MainWindow::pauseJob()
{
    qDebug() << "TODO: Here we need to pause the job";
}

void MainWindow::removeJob()
{
    qDebug() << "TODO: Here we need to remove the job";
}
